<?php
	
	namespace Aspic\Model;
	use Aspic as A;
	
	// TASK Make it implements ArrayAccess
	
	/**
	 * Should be extends to used with a DataModel. Then it could represent a product, client, ..
	 * This class can be serialzed but will not offer more than simple StdData class possibilities after unserializing it
	 * if you don't overide serialize methods
	*/
	class Row extends A\StdData {
		/**
		 * Define if the class take a DataModel in its constructor, maybe the 
		 * class extends Row and could define itself the DataModel used
		 */
		const TAKE_DATA_MODEL = true;
		
		/**
		 * @var DataModel
		 */
		protected $_dataModel = null;
		
		protected $_hasBeenModified = false;


		public function __construct(DataModel $dataModel, $returnNullIfEmpty = true) {
			parent::__construct(array(), $returnNullIfEmpty);
			
			$this->setDataModel($dataModel);
		}
		
		public function setDataModel(DataModel $dataModel) {
			$this->_dataModel = $dataModel;
		}
		
		public function set($var, $value) {
			$this->_hasBeenModified = true;
			
			return parent::set($var, $value);
		}
		
		/**
		 * Object cannot be store in file/database, this method return  
		 * a string (to store, maybe an object like a date object). 
		 * This make sennses in STRow class
		 * @see STROW
		 * @return string
		 */
		public function getStorableValue($var) {
			return parent::get($var);
		}
		
		public function getPrimaryKeyValue() {
			$pkName = $this->getDataModel()->getPrimaryKeyName();
			
			return $this->{$pkName};
		}
		
		public function isPrimaryKeySet() {
			return !is_null($this->getPrimaryKeyValue());
		}
		
		public function getDataModel() {
			return $this->_dataModel;
		}

		public function hasDataModel() {
			return ($this->getDataModel() !== null);
		}
		
	}
	
?>